#include <iostream>

long long const inf = (long long)(1) << 60;
int const maxn = 510;
int const maxv = 5100;
int v[maxn];
long long w[maxn];
long long f[maxn][maxv];
int n, b;

int main()
{
    std::ios::sync_with_stdio(false);
    int T; std::cin >> T;
    while (T--) {
        std::cin >> n >> b;
        for (int i = 1; i <= n; i++) std::cin >> w[i] >> v[i];

        for (int i = 0; i <= n; i++)
            for (int j = 0; j <= 5000; j++) f[i][j] = inf;

        int ans = 0;
        f[0][0] = 0;
        for (int i = 1; i <= n; i++) {
            f[i][0] = 0;
            for (int j = 1; j <= 5000; j++) {
                f[i][j] = f[i - 1][j];
                if (j >= v[i] && f[i - 1][j - v[i]] < inf)
                    f[i][j] = std::min(f[i][j], f[i - 1][j - v[i]] + w[i]);
                if (f[i][j] <= b) ans = std::max(ans, j);
            }
        }
        std::cout << ans << '\n';
    }
}

